﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace PPE_gestion_commercial
{
    public partial class Form3 : Form
    {
        SqlConnection connex;
        SqlCommand cmd;
        SqlDataReader dr;

        public static string selectionner;
        public static string type;

        public Form3(string selectionne, int colonne)
        {
            InitializeComponent();

            selectionner = selectionne;

            if (colonne == 0)
                type = "NomClient";
            else
                type = "PrenomClient";
        }

        private void Form3_Load(object sender, EventArgs e)
        {
            textBox1.Text = selectionner;

            string strconn = "data source=MANU-PC;database=gestion;trusted_connection=yes";
            connex = new SqlConnection();
            connex.ConnectionString = strconn;
            connex.Open();

            string sql = "Select * from client where "+type+"= '"+selectionner+"'";
            cmd = new SqlCommand(sql, connex);
            dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                textBox1.Text = dr[1].ToString();
                textBox2.Text = dr[2].ToString();
                textBox3.Text = dr[3].ToString() + " " +dr[4].ToString();
                textBox4.Text = dr[5].ToString();
                textBox5.Text = dr[6].ToString();
                textBox6.Text = dr[7].ToString();
                textBox7.Text = dr[8].ToString();
                textBox8.Text = dr[9].ToString();
            }

            dr.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
